import scrapy
from demo2.items import jinjiangItem
#scrapy crawl jinjiang -o jinjiang.csv
class JinjiangSpider(scrapy.Spider):
    name = "jinjiang"
    allowed_domains = ["jjwxc.net"]
    start_urls = ["https://www.jjwxc.net/topten.php?orderstr=5&t=0"]

    def parse(self, response):
        list_items = response.css('body > table:nth-child(23) > tbody > tr')
        for i in range(1,21):
            selector = list_items[i]
            item = jinjiangItem()
            item['serial_number'] = selector.css('td:nth-child(1)::text').get().strip()
            item['author'] = selector.css('td:nth-child(2) a::text').get().strip()
            item['title'] = selector.css('td:nth-child(3) a::text').get().strip()
            item['category'] = selector.css('td:nth-child(4)::text').get().strip()
            item['progress'] = selector.css('td:nth-child(5)::text').get().strip()
            item['word_count'] = selector.css('td:nth-child(6)::text').get().strip()
            item['work_points'] = selector.css('td:nth-child(7)::text').get().strip()
            item['publish_time'] = selector.css('td:nth-child(8)::text').get().strip()
            yield item

        pass
